﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ModelComponentModelInspector.cs" company="DissingNelleman">
//   
// All rights reserved. </copyright>
// <summary>
//   The model component model inspector.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ServiceLibrary.Hibernate
{
    using System.Reflection;

    using NHibernate.Mapping.ByCode;

    /// <summary>
    /// The model component model inspector.
    /// </summary>
    internal class ModelComponentModelInspector : SimpleModelInspector
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ModelComponentModelInspector"/> class.
        /// </summary>
        internal ModelComponentModelInspector()
        {
            this.IsVersion((m, declared) => this.IsVersion(m) || declared);
        }

        #endregion

        #region Methods

        /// <summary>
        /// The is version.
        /// </summary>
        /// <param name="m">
        /// The m.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool IsVersion(MemberInfo m)
        {
            var p = m as PropertyInfo;
            if (p == null)
            {
                return false;
            }

            if (p.PropertyType != typeof(int))
            {
                return false;
            }

            if (p.Name != "Version")
            {
                return false;
            }

            return true;
        }

        #endregion
    }
}